package com.hd.auto;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.xml.Parser;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.hd.bean.ASMDLoanApplicationReqTransBody;
import com.hd.bean.AnShuoRequest;
import com.hd.bean.ApplyEcm;
import com.hd.bean.ApplyInfo;
import com.hd.bean.BussinessFileUrl;
import com.hd.bean.IcrApplyInfo;
import com.hd.bean.IndContact;
import com.hd.bean.IndInfo;
import com.hd.bean.IndResume;
import com.hd.bean.IndSpouse;
import com.hd.until.AbstractHttpClient;
import com.hd.until.HttplTestUti;
import com.hd.until.IdGeneratorService;
import com.hd.until.InnerHttpResponse;

public class LoanReqToAnShuoTest extends AbstractTestNGSpringContextTests {

	// 家私贷
	public static final String JS_LOAN_APPLICATION = "HDJF-S-24";
	
	// 秒贷
    public static final String MD_LOAN_APPLICATION = "HDJF-S-21";
    
    //大额业主贷
    public static final String DE_LOAN_APPLICATION = "HDJF-S-22";
    

	private ApplyInfo applyInfo;

	private IndInfo indInfo;

	private IndResume indResume;

	private IndSpouse indSpouse;

	private List<IndContact> indContact;

	private List<ApplyEcm> applyEcm;
	
	private IcrApplyInfo icrApplyInfo;
	
	private BussinessFileUrl bussinessFileUrl;
	
	private Map<String, String> map;

	public LoanReqToAnShuoTest(Map<String, String> map) {
		this.map = map;
		applyInfo = getApplyInfo(map);
		indInfo = getIndInfo(map);
		indResume = getIndResume(map);
		indSpouse = getIndSpouse(map);
		indContact = getIndContact(map);
		icrApplyInfo = getIcrApplyInfo(map);
		bussinessFileUrl = getBussinessFileUrl(map);
		indContact = getIndContact(map);
		applyEcm = getApplyEcm(map);
	}

	public String sendReqToAnShuoTest() {

		String resp = "";
		// 1、拼装参数，返回一个java对象AnShuoRequest
		ASMDLoanApplicationReqTransBody transBody = getLoanApplicationReq();
		AnShuoRequest req = null;
		if("JSD".equals(map.get("loanType"))){
			req = new AnShuoRequest(JS_LOAN_APPLICATION, transBody);
		}else if("MD".equals(map.get("loanType"))){
			req = new AnShuoRequest(MD_LOAN_APPLICATION, transBody);
		}else{
			req = new AnShuoRequest(DE_LOAN_APPLICATION, transBody);
		}
//		AnShuoRequest req = new AnShuoRequest(JS_LOAN_APPLICATION, transBody);
		
		System.err.println(JSON.toJSONString(req,
				SerializerFeature.WriteMapNullValue,
				SerializerFeature.DisableCircularReferenceDetect));

		// 2、组装请求消息头
		// 4、发送http请求
		resp = HttplTestUti.doPostHttps(JSON.toJSONString(req,
				SerializerFeature.WriteMapNullValue,
				SerializerFeature.DisableCircularReferenceDetect));
		// 5、处理http响应
		
		return resp;

	}

	public ASMDLoanApplicationReqTransBody getLoanApplicationReq() {
		ASMDLoanApplicationReqTransBody transBody = new ASMDLoanApplicationReqTransBody();
		transBody.setIndInfo(indInfo);
		transBody.setApplyInfo(applyInfo);
		transBody.setIndResume(indResume);
		transBody.setIndSpouse(indSpouse);
		transBody.setApplyEcm(applyEcm);
		transBody.setIcrApplyInfo(icrApplyInfo);
		transBody.setBussinessFileUrl(bussinessFileUrl);
		transBody.setIndContact(indContact);
		return transBody;
	}

	public ApplyInfo getApplyInfo(Map<String, String> map) {
		ApplyInfo applyInfo = new ApplyInfo();
		applyInfo.setAppSerialNo(map.get("loanApplicatinNo"));
		applyInfo.setBusinessCurrency("CNY");
		applyInfo.setBusinessSum(map.get("loanSum"));
		applyInfo.setSpecificSerialNo(map.get("specificserialno"));
		applyInfo.setTimeLimit("3");
		applyInfo.setCorpusPaymethod(map.get("repaymentType"));
		applyInfo.setPayFrequencyType("1");
		applyInfo.setExecuteYearRate("0.16");
		applyInfo.setPurposeType("16");
		applyInfo.setComAccountNo(map.get("bankCardNo"));
		applyInfo.setComAccountName(map.get("memberName"));
		applyInfo.setComBankName(map.get("bankName"));
		applyInfo.setComBankNo(map.get("bankNo"));
		applyInfo.setComAccountPhone(map.get("mermberPhone"));
		applyInfo.setHouseAdd("东莞百悦尚城1060号586单元867");
		applyInfo.setProductLevel("M3");
		applyInfo.setSpecialpositionflag("0");
		applyInfo.setFeeRate(map.get("feeRate"));
		applyInfo.setCutRate(map.get("cutRate"));
		applyInfo.setHouseCity("441900");
		applyInfo.setBusinessSource("1");
		applyInfo.setHousePropertySerialno("3929");
		return applyInfo;
	}

	public IndInfo getIndInfo(Map<String, String> map) {
		IndInfo indInfo = new IndInfo();
		indInfo.setFullName(map.get("memberName"));
		indInfo.setCertType("1");
		indInfo.setCertId(map.get("certId"));
		indInfo.setSex("1");
		indInfo.setAge("18");
		indInfo.setBirthday("2000-01-21");
		indInfo.setEdudegree("1");
		indInfo.setMarriage("1");
		indInfo.setChildrenStatus("1");
		indInfo.setCecusRegisterAdd("110101");
		indInfo.setFamilyCity("441900");
		indInfo.setFamilyAdd("东莞百悦尚城1060号586单元867");
		indInfo.setHouseProperties("02");
		indInfo.setMobile(map.get("mermberPhone"));
		indInfo.setEmail("yu@hd.com");
		indInfo.setMemberid(map.get("memberNo"));
		indInfo.setCardnum(map.get("bankCardNo"));
		indInfo.setAtmonthincome("30000");
		indInfo.setCityline("10");
		indInfo.setArea("10");
		indInfo.setPropertyfeetime("0");
		indInfo.setHousecontractno("D829315F-5DD1-41A8-AE15-E1A4C6C59A821");
		indInfo.setHousetotalprice("20");
		indInfo.setInitialpayment("20");
		indInfo.setInitialpaymentproportion("30");
		indInfo.setAum("150000");
		indInfo.setHDHouseAddress("东莞百悦尚城1060号586单元867");
		indInfo.setEduExperience("1");
		return indInfo;
	}

	public IndResume getIndResume(Map<String, String> map) {
		IndResume indResume = new IndResume();
		indResume.setEmployment("df");
		indResume.setCompanyCity("110101");
		indResume.setCompanyTel("020-22222222");
		return indResume;
	}

	public IndSpouse getIndSpouse(Map<String, String> map) {
		IndSpouse indSpouse = new IndSpouse();
		indSpouse.setFullName(map.get("memberName"));
		indSpouse.setSpouseMobile(map.get("mermberPhone"));
		return indSpouse;
	}

	public List<IndContact> getIndContact(Map<String, String> map) {
		List<IndContact> indContact = new ArrayList<IndContact>();
		IndContact indContact1 = new IndContact();
		indContact1.setContractType("20");
		indContact1.setContactName("联系人");
		indContact1.setContactMobile("18999999999");
		indContact1.setRelationShip("1");
		indContact.add(indContact1);
		return indContact;
	}

	public List<ApplyEcm> getApplyEcm(Map<String, String> map) {
		List<ApplyEcm> applyEcm = new ArrayList<ApplyEcm>();
		ApplyEcm applyEcm1 = new ApplyEcm();
		applyEcm.add(applyEcm1);
		return applyEcm;
	}

	public IcrApplyInfo getIcrApplyInfo(Map<String, String> map) {
		IcrApplyInfo icrApplyInfo = new IcrApplyInfo();
		return icrApplyInfo;
	}

	public BussinessFileUrl getBussinessFileUrl(Map<String, String> map) {
		BussinessFileUrl bussinessFileUrl = new BussinessFileUrl();
		bussinessFileUrl.setIdCardPositive(map.get("certiPicPathFront"));
		bussinessFileUrl.setIdCardNegative(map.get("certiPicPathFront"));
		bussinessFileUrl.setHandHeldidCard(map.get("certiPicPathFront"));
		
		return bussinessFileUrl;
	}

	public static void main(String[] args) {
//		LoanReqToAnShuoTest an = new LoanReqToAnShuoTest();
//		ASMDLoanApplicationReqTransBody transBody = an.getRequestBody();
//		AnShuoRequest req = new AnShuoRequest(JS_LOAN_APPLICATION, transBody);
//		String content = JSON.toJSONString(req,
//				SerializerFeature.WriteMapNullValue,
//				SerializerFeature.DisableCircularReferenceDetect);
//		HttplTestUti.doPostHttps(content);
	}
}
